#coding:utf-8

"""
CopyRight(c)  2017-09-15  Fraplus Corp

Author: Xiaodong.yang
Email:  xiaodong.yang@unidt.com
Functions:

we chat server

dependence package:

fralog
handler

"""


import signal
import time
import tornado.ioloop
def loop():
    sp = SigProccess()
    while True:
        if sp.is_stop():
            print('用户退出')
            break
        else:
            print('Sleep....')
            time.sleep(1)


class SigProccess(object):
    def __init__(self, io = None):
        super(SigProccess).__init__()
        self._stop = False
        signal.signal(signal.SIGINT, self.sig_handler)
        signal.signal(signal.SIGTERM, self.sig_handler)
        signal.signal(signal.SIGABRT, self.sig_handler)
        self._ioloop = io

    def sig_handler(self, signum, frame):
        print('终止IOLOOP')
        if self._ioloop is not None:
            self._ioloop.close()
        self.set_stop()

    def set_stop(self):
        self._stop = True

    def is_stop(self):
        return self._stop


if __name__ == '__main__':
    loop()